<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script type="text/javascript">
			/*
 * instanceof: 判断是否属于某个类型，是否是某个对象
 */

//设置cookie
function setCookie(name, value, expires, path, domain, secure) {
    //name=value
    var cookieText = encodeURIComponent(name) + "=" + encodeURIComponent(value);
    //console.log("aaa: "+ cookieText);
    //失效时间
    if (expires instanceof Date) {
        cookieText += "; expires="+expires;
    }
    //path
    if (path) {
        cookieText += "; path="+path;
    }
    //domain
    if (domain) {
        cookieText += "; domain="+domain;
    }
    //secure
    if (secure) {
        cookieText += ";secure";
    }
    document.cookie = cookieText; //设置cookie
    return document.cookie;
}

//获取cookie
//name2=123; name5=456; name=789
function getCookie(name) {
    var cookie = decodeURIComponent(document.cookie);
    var arr = cookie.split("; ");
    for (var i=0; i<arr.length; i++) {
        //name5=456a=
        var arr2 = arr[i].split("=");
        if (arr2.length >= 2) {
            if (arr2[0] == name) {
                return arr2[1];
            }
        }
    }
    return "";
}

//删除cookie
function removeCookie(name) {
    var d = new Date();
    document.cookie = decodeURIComponent(name) + "=; expires=" + d;
    //console.log(name + "=; expires=" + d);
    return document.cookie;
}
//================
//			var d = new Date("2018-8-8");
//          var cookieText = setCookie("name5", "123", d);
//          var cookieText2 = setCookie("pass", "123456", d);
//          console.log(cookieText);
//			console.log(cookieText2);	
//          //获取name对应的value
//          var value = getCookie("name5");
//          console.log(value);
			
//          //删除cookie 对应name5的value
//          var cookieText = removeCookie("name5");
//          console.log("cookieText:"+cookieText);
//           console.log("document.cookie:"+document.cookie);

		</script>
	</head>
	<body>
	</body>
</html>
